////////////////////////////////////////////////////////////////////////////////
//(c) Intelliquip, Inc. 2001
////////////////////////////////////////////////////////////////////////////////
//$Log:
// 2    Version 10.0 (Current View)1.1         6/28/2011 11:59:26 AM  Stephen
//      Kish    IDD#10001:  Adding null check for user
// 1    Version 10.0 (Current View)1.0         4/20/2011 4:16:57 PM   Jeff
//      Heigl      
//$
//$NoKeywords$
////////////////////////////////////////////////////////////////////////////////
package com.intelliquip.hydraulicselection.control.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.intelliquip.core.Applications;
import com.intelliquip.core.servlet.MergedSessionFilter;
import com.intelliquip.core.servlet.MergedSessionHandler;
import com.intelliquip.hydraulicselection.UserPreferences;
import com.intelliquip.xmltransfer.OrganizationSettings;
import com.intelliquip.xmltransfer.UserXT;

public class MergedSessionFilter_Selector extends MergedSessionFilter {

	@Override
	protected MergedSessionHandler createHandler(HttpServletRequest request, HttpServletResponse response) {
		return new MergedSessionHandler_Selector(request);
	}


	private static class MergedSessionHandler_Selector extends MergedSessionHandler {

		private UserPreferences userPreferences;

		public MergedSessionHandler_Selector(HttpServletRequest request) {
			super(request);

			SessionAttributeDAO_Selector dao = new HttpSessionAttributeDAO_Selector(request.getSession());
			userPreferences = dao.getUserPreferences();
		}

		@Override
		protected String buildLogoutURL() {
			return Applications.getSelectorContextPath() + Applications.getSelectorServletPath() + Applications.getSelectorLogout();
		}

		@Override
		protected String getDynamicIDFromSessionBean() {
			UserXT user = userPreferences.getUser();
			if(user!=null) {
				return user.getDynamicID();
			} else {
				return null;
			}
		}

		@Override
		protected int getOrgIDFromSessionBean() {
			return userPreferences.getOrgID();
		}

		@Override
		protected OrganizationSettings getPartyOrgSetup() {
			return userPreferences.getPartyOrgSetup();
		}

		@Override
		protected boolean isSessionBeanNull() {
			return userPreferences == null;
		}
	}
}
